﻿<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>总部HSE日常管理</title>
    <!-- 公共 js CSS 文件 -->
    <script src="../static/js/common.js"></script>
    <script src="../static/js/Mock/Education.js"></script>
    <style>
        .upload-demo {
            width: 360px
        }

        .el-upload-list__item-name {
            height: 30px;
            color: #606266;
            display: block;
            margin-right: 40px;
            overflow: hidden;
            padding-left: 4px;
            text-overflow: ellipsis;
            transition: color .3s;
            white-space: nowrap;
        }
    </style>
</head>

<body>

    <div id="app">
        <el-upload class="upload-demo"
                   ref="upload"
                   action="/api/File/UpdateFile"
                   multiple="true"
                   :on-preview="handlePreview"
                   :on-remove="handleRemove"
                   :file-list="fileList"
                   :before-upload="beforeupload"
                   :auto-upload="true">
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
        </el-upload>

        <el-button type="primary" @click="onExcel">{{col.btnExcel}}</el-button>
    </div>
    <script>
        var Main = new Vue({
            el: '#app',
            data: {
                fileList: [{
                    name: 'food.jpeg',
                    url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
                },
                {
                    name: 'food2.jpeg',
                    url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
                }]

            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                submitUpload: function () {
                    this.$refs.upload.submit();
                    
                },
                handleRemove: function (file, fileList) {
                    console.log(file, fileList);
                },
                handlePreview: function (file) {

                    console.log(file);
                    window.open(file.url)
                },
                beforeupload :function(file) {
                    
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    const extension = testmsg === 'xls'
                    const extension2 = testmsg === 'xlsx'
                    const isLt2M = file.size / 1024 / 1024 < 10
                    if (!extension && !extension2) {
                        this.$message({
                            message: '上传文件只能是 xls、xlsx格式!',
                            type: 'warning'
                        });
                    }
                    if (!isLt2M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt2M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt2M
                },
                onExcel: function () {
                    myAjax("post", this, '/api/XXXXX/export', null,
                        function (response) { 
                            showMessage(response.message, 'success')
                        });
                }


            },
            mounted: function () {

              
            }

        });

    </script>


</body>

</html>